/*
 * CPlayEngine.h
 *
 *  Created on: 2009-5-8
 *      Author: Administrator
 */

#ifndef CPLAYENGINE_H_
#define CPLAYENGINE_H_

#include <videoplayer.h>
#include <e32base.h>

enum TState
{
	EPlayerNotReady,
	EPlayerReadyToPlay,
	EPlayerPlaying,
	EPlayerPlayComplete
};

class CPlayEngine : public MVideoPlayerUtilityObserver, public CBase
	{
private:
	void ConstructL(TInt aPriority,
			  TMdaPriorityPreference aPref,
			  RWsSession& aWs,
			  CWsScreenDevice& aScreenDevice,
			  RWindowBase& aWindow,
			  const TRect& aScreenRect,
			  const TRect& aClipRect);

	CPlayEngine();
public:
	
	virtual ~CPlayEngine();
	
	static CPlayEngine* NewL(TInt aPriority,
				  TMdaPriorityPreference aPref,
				  RWsSession& aWs,
				  CWsScreenDevice& aScreenDevice,
				  RWindowBase& aWindow,
				  const TRect& aScreenRect,
				  const TRect& aClipRect);

	static CPlayEngine* NewLC(TInt aPriority,
				  TMdaPriorityPreference aPref,
				  RWsSession& aWs,
				  CWsScreenDevice& aScreenDevice,
				  RWindowBase& aWindow,
				  const TRect& aScreenRect,
				  const TRect& aClipRect);
/**
 * CVideoPlayerUtility
 * Plays sampled video data.
 */
public:
/**
* Opens a video clip from a file.
* 
This function opens a video clip from a file using an optionally 
specified plugin. If no controller plugin is specified, this function
 searches through a list of all available plugins and attempts to 
 use each one until successful or the end of the list is reached.
 
Once the opening of the video clip is complete, successfully or
otherwise, the callback function MVideoPlayerUtilityObserver::MvpuoOpenComplete()
is called.

This function leaves if errors are encountered opening the specified
video clip file, or in initialising a specified/unspecified controller plugin.
 
This function can leave with one of the specified error codes. Most
open failures will however be reported through the MVideoPlayerUtilityObserver interface.
* 
* @param &aFileName
* The full path name of the file containing the video data. 
* 
* @param aControllerUid
* If specified, it will force the video player to use the controller with the given UID.
*/
	void OpenFileL(const TDesC& aFileName, TUid aControllerUid = TUid::Null());
	void OpenDesL(const TDesC8& aDescriptor, TUid aControllerUid= TUid::Null());
	void OpenUrlL(const TDesC &aUrl, TInt aIapId=KUseDefaultIap, const TDesC8 &aMimeType=KNullDesC8, TUid aControllerUid=TUid::Null());
	
/**
Begins playback of the initialised video sample at the current volume and priority levels.

When playing of the video sample is complete, successfully or otherwise, the callback 
function MVideoPlayerUtilityObserver::MvpuoPlayComplete() is called.
*/
	void PlayL();
	
/**
 * Stops playback of the video sample as soon as is possible.
 * 
If the video sample is playing, playback is stopped as soon 
as possible and the callback function MVideoPlayerUtilityObserver::MvpuoPlayComplete() 
is called.

If playback is already complete, this function has no effect.
In addition, under these circumstances the callback function 
MVideoPlayerUtilityObserver::MvpuoPlayComplete() is not called either.

The position is reset to the beginning of the file.
 * @param
 * An error code indicating if the function call was successful. 
 * KErrNone on success, otherwise another of the system-wide error codes.
 */
	TInt StopL();
	
/**
 * Closes the video clip.
 */
	void CloseL();
	
	
/** MVideoPlayerUtilityObserver
 * 
	An interface to a set of video player callback functions.
	
	The class is a mixin and is intended to be inherited by the 
	client class which is observing the video playing operation. 
	The functions encapsulated by this class are called when specific
	events occur in the process of initialising and playing an video
	clip. A reference to this object is passed as a parameter when 
	constructing an audio player utility object.
*/
	void PauseL();

	
	
public:
	
/** Notification to the client that the opening of the video clip has completed,
    successfully, or otherwise.
    
    The status of the video sample after opening is given by aError. The following
    values have the same meaning across all devices:
    
    KErrNone: the sample is ready to play;
    KErrNotSupported: the controller plugin is not recognised or not supported;
    KErrNotFound: the video sample cannot be found;
    KErrNoMemory: there is insufficient memory to play this video sample.

    Other values are possible indicating a problem opening the video sample. These 
    values are device dependent.
    
    The client must now call Prepare() on the video player utility before the video 
     clip can be played or any of its properties (e.g. duration) can be queried 
     
     @param  aError
	        The status of the video player after initialisation.
 */
	virtual void MvpuoOpenComplete(TInt aError);
	
/**
	Notification to the client that the opening of the video clip has been prepared
	successfully, or otherwise.  This callback is called in response to a call to
	CVideoPlayerUtility::Prepare().

	The video clip may now be played, or have any of its properties (e.g. duration) queried.

	@param  aError
    The status of the video player after initialisation.
    This is either KErrNone if the open has completed successfully,
    or one of the system wide error codes.		
*/	
	
	virtual void MvpuoPrepareComplete(TInt aError);
	
/**
	Notification that the frame requested by a call to GetFrameL is ready

	@param  aFrame
		    The returned frame. The bitmap will contain
		    the requested frame if the the error code is KErrNone (success).
	@param  aError
		    The status of the frame request.
		    This is either KErrNone if the frame request was successful,
		    or one of the system wide error codes.		
*/
	
	virtual void MvpuoFrameReady(CFbsBitmap& aFrame,TInt aError);
	
/**
	Notification that video playback has completed. This is not called if
	playback is explicitly stopped by calling Stop.

	@param  aError
		    The status of playback.
		    This is either KErrNone if the playback was completed successfully,
		    or one of the system wide error codes.
*/
	
	virtual void MvpuoPlayComplete(TInt aError);
	
/**
	General event notification from controller. These events are specified by
	the supplier of the controller

	@param  aEvent
		    The event sent by the controller.
*/
	
	virtual void MvpuoEvent(const TMMFEvent& aEvent);
	
protected:
	CVideoPlayerUtility* iPlayer;
	
public:
	TState iState;	

	};

#endif /* CPLAYENGINE_H_ */
